package cn.stronglink.assetmanage.business.repair.order;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.entity.Repair;
import cn.stronglink.assetmanage.entity.User;
import cn.stronglink.assetmanage.listener.onRecyclerListener;

/**
 * Author by chencongcong,Date on 2018/9/19
 */
public class RepaierOrderAdapter extends RecyclerView.Adapter<RepaierOrderAdapter.CheckViewHolder> {
    private List<Repair> mRepaierList;
    private Context mContext;
    private onRecyclerListener mListener;

    public void setListener(onRecyclerListener listener) {
        mListener = listener;
    }

    public RepaierOrderAdapter(Context context) {
        mContext = context;
    }

    @Override
    public CheckViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        View itemView = inflater.inflate(R.layout.item_check_order,null,true);
        RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        itemView.setLayoutParams(lp);
        return new CheckViewHolder(itemView, mListener);
    }

    @Override
    public void onBindViewHolder(CheckViewHolder holder, int position) {
        if (mRepaierList != null) {
            if (position%2==0){
                //偶数
                holder.llCheckItem.setBackgroundColor(mContext.getResources().getColor(R.color.colorWhite));
            }else{
                holder.llCheckItem.setBackgroundColor(mContext.getResources().getColor(R.color.gray_check_item));
            }
            holder.tvOrderNo.setText(mRepaierList.get(position).getId_());
            holder.tvOrderCreateDate.setText(mRepaierList.get(position).getCreateTime());
            holder.tvOrderCreateUser.setText(mRepaierList.get(position).getCreateName());
            holder.tvOrderPlayDate.setText(mRepaierList.get(position).getCreateTime());
            holder.tvOrderPlayUser.setText(mRepaierList.get(position).getOperatiorName());
            holder.tvOrderSupply.setText("");
        }
    }

    @Override
    public int getItemCount() {
        return mRepaierList == null ? 0 : mRepaierList.size();
    }

    public class CheckViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @BindView(R.id.ll_check_item)
        LinearLayout llCheckItem;
        @BindView(R.id.tv_check_order_no)
        TextView tvOrderNo;
        @BindView(R.id.tv_check_order_crate_date)
        TextView tvOrderCreateDate;
        @BindView(R.id.tv_check_order_crate_user)
        TextView tvOrderCreateUser;
        @BindView(R.id.tv_check_order_play_date)
        TextView tvOrderPlayDate;
        @BindView(R.id.tv_check_order_play_user)
        TextView tvOrderPlayUser;
        @BindView(R.id.tv_check_order_supply)
        TextView tvOrderSupply;
        private onRecyclerListener mListener;

        public CheckViewHolder(View itemView, onRecyclerListener listener) {
            super(itemView);
            this.mListener = listener;
            ButterKnife.bind(this, itemView);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (mListener != null) {
                mListener.onItemClicked(v, getAdapterPosition());
            }
        }
    }

    public void notifyDataChanged(List<Repair> mRepairList) {
        this.mRepaierList = mRepairList;
        this.notifyDataSetChanged();
    }
}
